<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>    
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 
 
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> 
<!--area_lista_serv.jsp-->  
<style>
td.alignCenter{
	text-align:center;
}
div.jtable-main-container div.jtable-title div.jtable-toolbar{
	right:114px;
	top:0px;
	bottom:auto;
}
</style>
<script type="text/javascript">
//var listaSorgenti =<c:out value="${listaSorgenti}" escapeXml="false" 	/>;
var listaAutisti =<c:out value="${listaAutisti}" escapeXml="false" 	/>;
//var listaClienti =<c:out value="${listaClienti}" escapeXml="false" 	/>;

    $(document).ready(function () {
        $('#listServizi').jtable({
        	defaultDateFormat: 'dd/mm/yy',
        	paging: true,
        	pagesize: 10,
        	pageList: 'minimal',
        	sorting: 'true',
            title: 'Lista Servizi <div id="filterDataButton"><img class="filterIcon" src="<%=request.getContextPath()%>/i/filter.png"> filter data</div>',
            toolbar: {
            	 hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
            	 hoverAnimationDuration: 60, //Duration of the hover animation.
           	     hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
            	    
                items: [{
                    icon: '/images/excel.png',
                    text: 'Export to Excel',
                    click: function () {
                        //perform your custom job...
                    }
                },{
                    icon: '/images/pdf.png',
                    text: 'Export to Pdf',
                    click: function () {
                        //perform your custom job...
                    }
                }]
            },
            actions: {
                listAction: '<%=request.getContextPath()%>/areaPrivata/ajax/loadServizi.html',
                createAction: '<%=request.getContextPath()%>/areaPrivata/ajax/newServizio.html',
                updateAction: '<%=request.getContextPath()%>/areaPrivata/ajax/editServizio.html',
                deleteAction: '<%=request.getContextPath()%>/areaPrivata/ajax/deleteServizio.html'
            },
            fields: {
                idServ: {
                    key: true,
                    list: false,
                    create: false,
                    edit: false
                },
                idServUserJson: {
                    title: 'Id',
                    width: '4%',
                    create: false,
                    edit: false,
                    display: function (data) {
                    	if (data.record) {
                    		return data.record.idServUser;
                    	}
                    }
                },
                idServUser: {
                    create: false,
                    type: 'hidden',
                    defaultValue: function (data) {return data.record.idServUser; }
                },
//                 idUserInse: {
//                     type: 'hidden'
//                 },
                tipoServizio: {
                	list: false,
                    title: 'Tipo Corsa',
                    width: '8%',
                    options: { '1': 'Transfer Privato', '2': 'Transfer Shuttle' , '3': 'Disposizione Oraria' }
                },   
            
                dataJson: {
                    title: 'Data',
                    width: '7%',
                    type: 'date',
                    //inputClass: 'validate[required,custom[date]]',
                    listClass: 'grassetto',
                    inputClass: 'validate[funcCall[checkData]]'
                },
                oraJson: {
                    title: 'Ora',
                    width: '3%',
                    sorting: false,
                	inputClass: 'validate[required,custom[orario]]'
                },
                dataInseJson: {
                    create: false,
                    edit: false,
                    type: 'hidden'
                    
                },
        
                'idCliente': {
                    type: 'hidden',
                 	defaultValue: function (data) {return data.record.cliente.idCliente; },
                	create: false
                },
                'cliente.descNome': {
                	title: 'Cliente',
                    width: '10%',
                    sorting: true,
	                 display: function (data) {
	                	 var str = data.record.cliente.descNome +'<br/>'+ data.record.cliente.telefono  +'<br/>'+ data.record.cliente.email;
	                     return str;
	                 },
	                input: function (data) {
	                    if (data.record) {
	                        return '<input type="text" name="cliente.descNome" style="width:200px" value="' + data.record.cliente.descNome + '" />';
	                    } else {
	                        return '<input type="text" name="cliente.descNome" style="width:200px" />';
	                    }
	                }
             	},
                'cliente.telefono': {
                	title: 'Tel.',
		            list: false,
		            
	                 display: function (data) {
	                     return data.record.cliente.telefono;
	                 },
	                input: function (data) {
	                		if (data.record) {
	                        	return '<input type="text" name="cliente.telefono" style="width:200px" value="' + data.record.cliente.telefono + '" />';
	                        } else {
	                        	return '<input type="text" name="cliente.telefono" style="width:200px" value="" />';
	                        }
	                }
             	},  
                'cliente.email': {
                	title: 'Email Cliente',
                    list: false,
	                 display: function (data) {
	                     return data.record.cliente.email;
	                 },
	                input: function (data) {
	                    if (data.record) {
	                        return '<input type="text" name="cliente.email" style="width:200px" value="' + data.record.cliente.email + '" />';
	                    } else {
	                        return '<input type="text" name="cliente.email" style="width:200px" />';
	                    }
	                }
             	},               	
                pax : {
                    title: 'Pax',
                    width: '3%',
                    options: ['1','2','3','4','5','6','7','8','altro' ],
                    sorting: false
                    
                },
                volo: {
                    title: 'Volo/Nave/Treno',
                    width: '5%'
                },
                
                pickUp: {
                    title: 'Da',
                    width: '17%'
                },
                dropOff: {
                    title: 'Destinazione',
                    width: '17%'
                },
                
                prezzo: {
                    title: '&euro;',
                    width: '4%',
                    listClass: 'grassetto',
                    defaultValue: '0',
                    display:	function (data) {
	                    if (data.record) {
	                        return '&euro; ' + data.record.prezzo;
	                    } 
                    }
                },  
//                 idSorgente : {
//                     title: 'Proveniente da collaboratore:',
//                     options: listaAutisti,
//                     list: false
//                 },
//                 idAutista : {
//                     title: 'Eseguito da',
//                     list: false,
//                     options: function (data) { return listaAutisti; }
//                 },
//                 nomeAutista : {
//                     title: 'Eseguito da',
//                     create: false,
//                     edit: false,
//                     display: function (data) { return data.record.nomeAutista; }
//                 },
                descTipoServizio: {
                    title: 'Tipo Corsa',
                    width: '8%',
                    edit: false,
                    create: false,
				    sorting: false
                },
                info: {
                    title: 'Info',
                    width: '8%',
				    sorting: false
                },       
                 Scambia : {
                	  edit: false,
                      create: false,
  				     sorting: false,
                     title: 'Invia a Scambio',
					 listClass:'alignCenter',
                     display: function (data) {
                          return '<a href="#">  <img src="<%=request.getContextPath()%>/i/corsa_out.png" alt="in" width="29" height="23" /> </a>';
                     }
                 }
                    
            },
            //Initialize validation logic when a form is created
            formCreated: function (event, data) {
				console.log($(data.form).attr("id"));
                data.form.validationEngine();
            },
            //Validate form when it is being submitted
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            //Dispose validation logic when form is closed
            formClosed: function (event, data) {
			
                data.form.validationEngine('hide');
                //data.form.validationEngine('detach');
            }
        });
        
        $('#listServizi').jtable('load');

    });
    
    
    function checkData(field, rules, i, options){
	
	console.log(field.attr("secondValidationCall"));
	
	if(field.attr("secondValidationCall")!=null && field.attr("secondValidationCall")){
		 var pattern = /^(0?[1-9]|[12][0-9]|3[01])[\/\-\.](0?[1-9]|1[012])[\/\-\.]([0-9]{4})$/; 
    		    var str = field.val();
				//alert(str);
    		    // if (!str.match(pattern)) {
    	    	     // return options.allrules.validate2fields.alertText;

    		    // }
				console.log(str);
				if(str===""){
				console.log("innnn");
					//alert("innnn");
					rules.push('required');  
					//return options.allrules.validate2fields.alertText;
				}
		field.attr({"secondValidationCall":""});
	}
	else{
		setTimeout(function(){
			field.attr({"secondValidationCall":"secondValidationCall"});
			$('#jtable-create-form').validationEngine('validateField', '#Edit-dataJson'); 
			
		},1000);
    }    
    	     // this allows the use of i18 for the error msgs
   }

    
    
    

    
</script>
			
			
	<!-- INIZIO CONTENUTO -->
				
<div id="listServizi" class="listaJtable"></div>
	<!-- FINE CONTENUTO -->



<div id="listServizi_filterspopup" class="filterpopup">

	<div class=filterCell><span>start date:</span><input id="startDate"/></div>
	<div class=filterCell><span>end date:</span><input id="endDate"/></div>
	<div class=buttonrow>
	<a id="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icons insertButton" role="button" aria-disabled="false" style="margin-right:5px;">
		<span style='color:#000000;  padding-top:2px;padding-bottom:2px; font-size:11px; padding:6px 1.5em;' class="ui-button-text">load</span>
	</a>
	<a id="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icons insertButton" role="button" aria-disabled="false" onclick="javascript:closeFilterDiv();">
		<span style='color:#000000;padding-top:2px;padding-bottom:2px;font-size:11px;padding:6px 1.5em;' class="ui-button-text">close</span>
	</a>
	</div>
</div>


<script>
	$(document).ready(function(){
		$("#listServizi_filterspopup").css({
				"left":$("#filterDataButton").position().left-$("#listServizi_filterspopup").outerWidth()+$("#filterDataButton").outerWidth(),
				"top":$("#filterDataButton").position().top+30
			});
		$("#filterDataButton").after($("#listServizi_filterspopup"));
		$("#filterDataButton").click(function(){
			$("#listServizi_filterspopup").show();
			
		})
		$( "#startDate" ).datepicker();
		$( "#startDate" ).datepicker( "option", "showAnim", "slideDown" );
		$( "#endDate" ).datepicker();
		$( "#endDate" ).datepicker( "option", "showAnim", "slideDown" );
		
	})

	function closeFilterDiv(){
		$("#listServizi_filterspopup").hide();
		
	}
</script>









</div>
		</div>			